var app = getApp()
var orderModel = require('../../model/orderModel.js')
var util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var id = options.id
    this.setData({
      id:id,
    })
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    // this.setData({
    //   order: app.data.tempOrder
    // })
    this.init()
  },
  init() {
    var that=this
    util.showLoading("加载中")
    orderModel.getOrderInfo(this.data.id,res=>{
      wx.hideLoading()
      if(res.status==1){
        util.failToast(res.msg)
        return
      }
      that.setData({
        order:res.data
        
      })
    })
  },
  //商品/卡详情
  navToInfo(e) {
    var data = e.currentTarget.dataset.data
    this.toGoodsInfo(data)
  },
  //商品/卡详情
  toGoodsInfo(data) {
    var url
    if (data.type < 10)
      url = '../goods_info/goods_info?id=' + data.pid + "&type=" + data.type
    else
      url = '../card_info/card_info?id=' + data.pid + "&type=" + data.type
    wx.navigateTo({
      url: url
    })
  },
  //申请退款页面
  navToRefund() {
    app.data.tempOrder=this.data.order
    wx.navigateTo({
      url: '../user_order_refund/user_order_refund',
    })
  },
  //评价页面
  navToEvaluate(e) {
    app.data.tempOrder = this.data.order
    wx.navigateTo({
      url: '../user_order_evaluate/user_order_evaluate',
    })
  },
  //评价详情页面
  navToEvaluateInfo(e) {
    app.data.tempOrder = this.data.order
    wx.navigateTo({
      url: '../user_order_evaluate_info/user_order_evaluate_info',
    })
  },
    //待付款订单-付款
  bindPayOrder(e) {
    var order=this.data.order
    var id = order.id
    var that = this
    var type = 0;
    // 入团订单
    if (order.tuanRecordId != 0) type = 2
    //建团订单
    else if (order.tuanId != 0) type = 1
    orderModel.payOrder(id, type, res => {
      if (res.status == 1) {
        util.failToast(res.msg)
        setTimeout(()=>{
          wx.navigateBack()
        },800)
        return
      }
      util.successToast(res.msg)
      if (type != 0&&res.data.status==3) {//建团/入团成功
        setTimeout(() => {
          wx.redirectTo({
            url: '../tuan_join/tuan_join?trId=' + res.data.trId,
          })
        }, 1000)
      } else {
        setTimeout(that.init,1000)
      }
    })
  },
})